<?php
function echoTeamRow($id, $team) {
    $link = $team->getRosterLink();
    $points = $team->getPoints();
    echo<<< EOQ
      		<tr class="row$id">
      			<td>$link<td>
      			<td><input type="text" name="adjustment$team->id" value="$team->adjustment" maxlength="4" size="4"/></td>
      			<td>$points</td>
      		<tr>
EOQ;
}

include_once ("includes/init.php");

$submit = getParam("submit");
if (isset ($submit)) {
    foreach ($teams->teams as $team) {
        $adjustment = getVariable("adjustment", $team->id, $_POST);
        if (isset($adjustment) and strlen($adjustment) > 0) {
        	executeQuery("update seasons_teams set point_adjustment=$adjustment where fk_team_id=$team->id and fk_season_id=$season->id");
        }
    }

    $teams = new Teams();
    $md = new MatchDao();
    $matches = $md->findSeasonMatches($season);
	$_SESSION["teams"] = $teams;
	$_SESSION["matches"] = $matches;
}

include_once ("includes/header.php");

echo<<< EOQ
          <caption><h1>Team Point Adjustments</h1></caption>
      <tr>
        <td>
      <P class="small">This page allows the league commissioner to arbitarily adjust the league points for each team.
      </td>
      <tr>
      	<td>
      		<table border="0" cellPadding="5" cellSpacing="0">
      		<tr>
      			<th>Team<th>
      			<th>Adjustment</th>
      			<th>Adjusted Points</th>
      		<tr>
			<form action="adjustments.php" method="POST">
EOQ;
$i = 1;
foreach ($teams->teams as $team) {
    echoTeamRow($i, $team);
    if ($i == 1) {
        $i = 2;
    } else {
        $i = 1;
    }
}
echo<<< EOQ
	<tr>
		<td colspan="3" align="center">
			<input type="submit" name="submit" value="Update">
			</form>
		</td>
	</tr>
	</table></td></tr>
EOQ;

include ("includes/footer.php");
?>